<template>
	<view class="index" :style="{'height':windowHeight}">
		<clothes></clothes>
		<view class="binding">
			<view class="bindings">
				<view class="bindings-one">
					<view class="bindings-one-left">已绑定手机</view>
					<view class="bindings-one-rig">
						<input type="text" placeholder="请输入已绑定手机"/>
					</view>
				</view>
				<view class="bindings-one">
					<view class="bindings-one-left">绑定手机</view>
					<view class="bindings-one-rig">
						<input type="text" placeholder="请输入绑定手机"/>
					</view>
				</view>
				<view class="bindings-one">
					<view class="bindings-one-left" style="padding-top: 15rpx;">验证码</view>
					<view class="bindings-one-rigg">
						<view class="bindings-one-rig" style="padding-top: 15rpx;">
							<input type="text" placeholder="请输入验证码"/>
						</view>
						<view class="rig-btn" v-if="timeState == 0" @click="YanZhengMa">发送验证码</view>
						<view class="rig-btn" v-if="timeState == 1">{{time}}</view>
					</view>
				</view>
			</view>
			
			<view class="bindings-txt">您已经绑定过手机号码，如果再次绑定将取消之前绑定记录</view>
			<view class="bindings-btn">提交</view>
		</view>
	</view>
</template>
<script>
	export default {
		components: {},
		data() {
			return {
				windowHeight: "200px", 
				timeState:0,
				time:59,
			}
		},
		onLoad() {
			this.GaoDu() //判断手机高度
		},
		methods: {
			
			YanZhengMa(){
				let that = this
				this.sendSmsCodeIot()
			},
			sendSmsCodeIot() {
				let that = this
				uni.request({
					url: this.$api.sendSmsCodeIot, //仅为示例，并非真实接口地址。
					data: {
						mapping: this.mapping,
						mobile: this.mobile,
						deviceId: this.deviceId,
						scene: 1,
					},
					method: 'POST',
					header: {
						['tenant-id']: `${'1'}`
					},
					success: (res) => {
						if(res.data.code == 200){
							uni.showToast({
								duration: 1000,
								title:'发送成功',
								icon: 'none',
							})
							this.timeState = 1
							that.TimeS()
							console.log(res.data);
							this.access_token = res.data.data.access_token
							uni.setStorage({
								key: 'token',
								data: this.access_token,
								success: function() {
									console.log('success');
								}
							});
							setTimeout(() => {
								this.UserInfo(res.data.data.access_token) //用户信息
							}, 1000)
						}else{
							uni.showToast({
								duration: 1000,
								title:res.data.msg,
								icon: 'none',
							})
						}
						
					}
				});
			},
			TimeS() {
				this.timer = setInterval(() => {
					if (this.time != 0) {
						this.time = this.time - 1
					} else {
						clearInterval(this.timer)
						this.timeState = 0
						this.time = 59
					}
				}, 1000)
			},
			
			// 判断手机高度
			GaoDu() {
				console.log('12356')
				// 判断手机页面的高度
				uni.getSystemInfo({

					success: (res) => {
						this.windowHeight = res.windowHeight + "px";
					}
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.index {
		width: 100%;
		height: 100%;
		background: #ECF4FF;
	}
	.binding{
		padding: 25rpx;
	}
	.bindings{
		
		padding: 25rpx 25rpx 0rpx 25rpx;
		background: #fff;
	}
	.bindings-one{
		display: flex;
		padding-bottom: 25rpx;
		border-bottom: 3rpx solid #F3F3F3;
		margin-bottom: 25rpx;
	}
	.bindings-one-left{
		width: 180rpx;
		font-size: 30rpx;
		
	}
	.bindings-one-rig{
		font-size: 28rpx;
	}
	.bindings-one-rigg{
		display: flex;
		flex-wrap: nowrap;
		justify-content:space-between;
		width: 68%;
	}
	.rig-btn{
		background: #607EF5;
		width: 180rpx;
		height: 70rpx;
		font-size: 28rpx;
		text-align: center;
		line-height: 70rpx;
		color: #fff;
		border-radius: 15rpx;
	}
	.bindings-txt{
		font-size: 26rpx;
		color: #E7888A;
		margin-bottom: 80rpx;
	}
	.bindings-btn{
		background: #6C74F1;
		width: 80%;
		margin: auto;
		height: 80rpx;
		border-radius: 100rpx;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		
	}

</style>